package com.itheima.mapper;

import com.itheima.pojo.Article;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface HomePageMapper {

	//查询所有文章（详细）
	@Select("select a.id,a.title,a.content,a.cover_img,a.update_time,a.likes,c.category_name,u.nickname,u.user_pic " +
			"from article a,user u,category c " +
			"where u.id = a.create_user and c.id=a.category_id " +
			"and a.state = '已发布' and a.title like '%${kw}%' ")
	List<Article> lists(String kw);

	//查询所有文章（详细）
	@Select("select a.id,a.title,a.content,a.cover_img,c.category_name,a.likes,a.update_time,u.nickname,u.user_pic " +
			"from article a,user u,category c " +
			"where u.id = a.create_user and c.id=a.category_id " +
			"and a.state = '已发布' and a.id = #{id}")
	List<Article> findById(int id);

	//	赞
	@Update("UPDATE article SET likes=likes+1")
	void findlike();
}
